package com.iplant.aps.service.po.aps;


import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.aps.service.po.oms.OMSOrder;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.base.utils.annotation.join.multi.DBJoinMulti;
import com.iplant.base.utils.annotation.po.DBBasePO;
import com.iplant.pdm.service.po.bop.FPCRoutePartPoint;

import java.util.*;

@DBBasePO(TableName = "aps_task_partpoint", Name = false,
        CheckName = {"Code"}, CodeAuto = true, CodePrefix = "APSN" +
        "-{yyMM}-",
        Schemas = DBSchemas.APS)
public class APSTaskPartPoint extends BasePO {

    public APSTaskPartPoint() {
        super();
    }

    public APSTaskPartPoint(FPCRoutePartPoint wFPCRoutePart, OMSOrder wOMSOrder) {
        super();
        LineID = wOMSOrder.LineID;
        OrderID = wOMSOrder.ID;
        ProductID = wOMSOrder.ProductID;
        RoutePartID = wFPCRoutePart.ID;
        StationID = wFPCRoutePart.StationID;
        PartPointType = wFPCRoutePart.PartPointType;
        PlanNum = wOMSOrder.FQTYPlan;
    }

    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int OrderID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "oms_order", tableAsName = "o1",
            Schemas = DBSchemas.APS,
            MainTableField = "OrderID")
    public String OrderNo = "";

    @DBCondition
    @DBField
    public int LineID = 0;

    /**
     * 产线
     */
    @DBJoin(name = "Name", tableName = "fmc_line", tableAsName = "fmc_line1", Schemas = DBSchemas.PDM,
            MainTableField = "LineID")
    public String LineName = "";

    @DBCondition
    @DBField
    public int ProductID = 0;

    @DBJoin(name = "Code", tableName = "fpc_product", tableAsName = "fpc_product1", Schemas = DBSchemas.PDM,
            MainTableField = "ProductID")
    public String ProductCode = "";

    @DBJoin(name = "ComponentNumber", tableName = "fpc_product", tableAsName = "fpc_product1", Schemas = DBSchemas.PDM,
            MainTableField = "ProductID")
    public int ComponentNumber = 1;

    @DBCondition
    @DBField
    public int RoutePartID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public String RoutePartName = "";

    @DBJoin(name = "Code", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public String RoutePartCode = "";

    @DBJoin(name = "OrderID", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public int RoutePartOrder = 0;

    @DBJoin(name = "WorkShopID", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public int WorkShopID = 0;

    @DBJoin(name = "WorkAreaID", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public int WorkAreaID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int RoutePartPointID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "fpc_routepartpoint", tableAsName = "fpc_routepartpoint1", Schemas =
            DBSchemas.PDM,
            MainTableField = "RoutePartPointID")
    public String RoutePartPointName = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "fpc_routepartpoint", tableAsName = "fpc_routepartpoint1", Schemas =
            DBSchemas.PDM,
            MainTableField = "RoutePartPointID")
    public String RoutePartPointCode = "";

    @DBJoin(name = "ComponentType", tableName = "fpc_routepartpoint", tableAsName = "fpc_routepartpoint1", Schemas =
            DBSchemas.PDM,
            MainTableField = "RoutePartPointID")
    public int ComponentType = 0;

    @DBJoin(name = "ScanComponentType", tableName = "fpc_routepartpoint", tableAsName = "fpc_routepartpoint1",
            Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartPointID")
    public int ScanComponentType = 0;


    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int TaskPartID;

    /**
     * 是否为当前版本
     */
    @DBCondition
    @DBJoin(name = "IsCurrent", tableName = "aps_task_part", tableAsName = "aps_task_part1", Schemas = DBSchemas.APS,
            MainTableField = "TaskPartID", JoinIndex = 2)
    public int IsCurrent = 0;

    @DBCondition
    @DBField
    public List<Integer> StationID = new ArrayList<Integer>();
    @DBJoinMulti(Name = "Name", MainTableField = "StationID", TableName = "fmc_station", Schemas = DBSchemas.Basic
    )
    public String StationName = "";
    @DBJoinMulti(Name = "Code", MainTableField = "StationID", TableName = "fmc_station", Schemas = DBSchemas.Basic
    )
    public String StationCode = "";
    @DBCondition(CompareType = DBCondition.DBCompareType.ge, ParamName = "StartTime")
    @DBField
    public Calendar PartPointStartTime = Calendar.getInstance();

    @DBCondition(CompareType = DBCondition.DBCompareType.lt, ParamName = "EndTime")
    @DBField
    public Calendar PartPointEndTime = Calendar.getInstance();
    @DBField
    public float PlanNum = 0.0f;


    /**
     * 排程类型  月 周
     */
    @DBCondition
    @DBField
    public int ShiftPeriod = 0;

    /**
     * 工序类型
     */
    @DBField
    public int PartPointType = 0;

    /**
     * 每天多少个
     */
    @DBField
    public Map<String, Float> PlanDayNum = new HashMap<>();

    /**
     * 每天  排程情况
     */
    @DBField
    public Map<String, List<APSCapacityUsed>> PlanDayDetailNum = new HashMap<>();

    @JsonProperty("PlanMargin")
    public float getPlanMargin() {
        if (PlanDayNum == null || PlanDayNum.size() == 0)
            return PlanNum;

        return PlanNum - PlanDayNum.values().stream().reduce(Float::sum).orElse(0.0f);
    }


    /**
     * 实际执行数量
     */
    @DBField
    public float ActNum = 0.0f;


    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int Status = 0;

    /**
     * 辅助属性（排序用）
     */
    @DBJoin(name = "OrderID", tableName = "fpc_routepartpoint", tableAsName = "fpc_routepartpoint1", Schemas =
            DBSchemas.PDM,
            MainTableField = "RoutePartPointID")
    public int RoutePartPointOrder = 0;

    /**
     * 历史完成数
     */
    @DBField
    public float HisActNum = 0.0f;

    @JsonProperty("RoutePartPointOrder")
    public int getRoutePartPointOrder() {
        return RoutePartPointOrder;
    }

    public void setRoutePartPointOrder(int routePartPointOrder) {
        RoutePartPointOrder = routePartPointOrder;
    }

    @JsonProperty("OrderID")
    public int getOrderID() {
        return OrderID;
    }

    public void setOrderID(int orderID) {
        OrderID = orderID;
    }

    @JsonProperty("OrderNo")
    public String getOrderNo() {
        return OrderNo;
    }

    public void setOrderNo(String orderNo) {
        OrderNo = orderNo;
    }

    @JsonProperty("LineID")
    public int getLineID() {
        return LineID;
    }

    public void setLineID(int lineID) {
        LineID = lineID;
    }

    @JsonProperty("ProductID")
    public int getProductID() {
        return ProductID;
    }

    public void setProductID(int productID) {
        ProductID = productID;
    }

    @JsonProperty("ProductCode")
    public String getProductCode() {
        return ProductCode;
    }

    public void setProductCode(String productCode) {
        ProductCode = productCode;
    }

    @JsonProperty("RoutePartID")
    public int getRoutePartID() {
        return RoutePartID;
    }

    public void setRoutePartID(int routePartID) {
        RoutePartID = routePartID;
    }

    @JsonProperty("RoutePartName")
    public String getRoutePartName() {
        return RoutePartName;
    }

    public void setRoutePartName(String routePartName) {
        RoutePartName = routePartName;
    }

    @JsonProperty("RoutePartPointID")
    public int getRoutePartPointID() {
        return RoutePartPointID;
    }

    public void setRoutePartPointID(int routePartPointID) {
        RoutePartPointID = routePartPointID;
    }

    @JsonProperty("RoutePartPointName")
    public String getRoutePartPointName() {
        return RoutePartPointName;
    }

    public void setRoutePartPointName(String routePartPointName) {
        RoutePartPointName = routePartPointName;
    }

    @JsonProperty("TaskPartID")
    public int getTaskPartID() {
        return TaskPartID;
    }

    public void setTaskPartID(int taskPartID) {
        TaskPartID = taskPartID;
    }

    @JsonProperty("StationID")
    public List<Integer> getStationID() {
        return StationID;
    }

    public void setStationID(List<Integer> stationID) {
        StationID = stationID;
    }

    @JsonProperty("StationName")
    public String getStationName() {
        return StationName;
    }

    public void setStationName(String stationName) {
        StationName = stationName;
    }

    @JsonProperty("StationCode")
    public String getStationCode() {
        return StationCode;
    }

    public void setStationCode(String stationCode) {
        StationCode = stationCode;
    }

    @JsonProperty("PartPointStartTime")
    public Calendar getPartPointStartTime() {
        return PartPointStartTime;
    }

    public void setPartPointStartTime(Calendar partPointStartTime) {
        PartPointStartTime = partPointStartTime;
    }

    @JsonProperty("PartPointEndTime")
    public Calendar getPartPointEndTime() {
        return PartPointEndTime;
    }

    public void setPartPointEndTime(Calendar partPointEndTime) {
        PartPointEndTime = partPointEndTime;
    }

    @JsonProperty("PlanNum")
    public float getPlanNum() {
        return PlanNum;
    }

    public void setPlanNum(float planNum) {
        PlanNum = planNum;
    }

    @JsonProperty("ShiftPeriod")
    public int getShiftPeriod() {
        return ShiftPeriod;
    }

    public void setShiftPeriod(int shiftPeriod) {
        ShiftPeriod = shiftPeriod;
    }

    @JsonProperty("PartPointType")
    public int getPartPointType() {
        return PartPointType;
    }

    public void setPartPointType(int partPointType) {
        PartPointType = partPointType;
    }

    @JsonProperty("PlanDayNum")
    public Map<String, Float> getPlanDayNum() {
        return PlanDayNum;
    }

    public void setPlanDayNum(Map<String, Float> planDayNum) {
        PlanDayNum = planDayNum;
    }

    @JsonProperty("PlanDayDetailNum")
    public Map<String, List<APSCapacityUsed>> getPlanDayDetailNum() {
        return PlanDayDetailNum;
    }

    public void setPlanDayDetailNum(Map<String, List<APSCapacityUsed>> planDayDetailNum) {
        PlanDayDetailNum = planDayDetailNum;
    }

    @JsonProperty("ActNum")
    public float getActNum() {
        return ActNum;
    }

    public void setActNum(float actNum) {
        ActNum = actNum;
    }

    @JsonProperty("Status")
    public int getStatus() {
        return Status;
    }

    public void setStatus(int status) {
        Status = status;
    }

    @JsonProperty("LineName")
    public String getLineName() {
        return LineName;
    }

    public void setLineName(String lineName) {
        LineName = lineName;
    }

    @JsonProperty("ComponentNumber")
    public int getComponentNumber() {
        return ComponentNumber;
    }

    public void setComponentNumber(int componentNumber) {
        ComponentNumber = componentNumber;
    }

    @JsonProperty("ComponentType")
    public int getComponentType() {
        return ComponentType;
    }

    public void setComponentType(int componentType) {
        ComponentType = componentType;
    }

    @JsonProperty("WorkShopID")
    public int getWorkShopID() {
        return WorkShopID;
    }

    public void setWorkShopID(int workShopID) {
        WorkShopID = workShopID;
    }

    @JsonProperty("WorkAreaID")
    public int getWorkAreaID() {
        return WorkAreaID;
    }

    public void setWorkAreaID(int workAreaID) {
        WorkAreaID = workAreaID;
    }

    @JsonProperty("ScanComponentType")
    public int getScanComponentType() {
        return ScanComponentType;
    }

    public void setScanComponentType(int scanComponentType) {
        ScanComponentType = scanComponentType;
    }

    @JsonProperty("RoutePartCode")
    public String getRoutePartCode() {
        return RoutePartCode;
    }

    public void setRoutePartCode(String routePartCode) {
        RoutePartCode = routePartCode;
    }

    @JsonProperty("RoutePartPointCode")
    public String getRoutePartPointCode() {
        return RoutePartPointCode;
    }

    public void setRoutePartPointCode(String routePartPointCode) {
        RoutePartPointCode = routePartPointCode;
    }

    @JsonProperty("IsCurrent")
    public int getIsCurrent() {
        return IsCurrent;
    }

    public void setIsCurrent(int isCurrent) {
        IsCurrent = isCurrent;
    }

    @JsonProperty("HisActNum")
    public float getHisActNum() {
        return HisActNum;
    }

    public void setHisActNum(float hisActNum) {
        HisActNum = hisActNum;
    }

    @JsonProperty("RoutePartOrder")
    public int getRoutePartOrder() {
        return RoutePartOrder;
    }

    public void setRoutePartOrder(int routePartOrder) {
        RoutePartOrder = routePartOrder;
    }


}



